/**
 * Package:com.afteryuan.server.game.handler;
 * $Id$
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.server.game.handler;

import com.afteryuan.server.handler.Handler;
import com.afteryuan.server.ConnectSession;
import com.afteryuan.server.data.Room;
import com.afteryuan.server.data.Sprite;
import com.afteryuan.server.data.SpritePool;
import com.afteryuan.server.service.SpriteService;
import com.afteryuan.server.game.command.up.SkillSingleUp;
import com.afteryuan.server.game.command.up.SkillScopeUp;
import com.afteryuan.server.game.command.down.SkillSingleDown;
import com.afteryuan.server.game.command.down.SkillScopeDown;
import com.afteryuan.server.command.up.CommandUp;

/**
 * SkillSingleHandler
 * <p/>
 * 处理步骤:
 * 1.判断技能是否合法.
 * 2.如果合法,则广播给指定范围(目前为全空间广播)
 * <p><a href="SkillSingleHandler.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author$</a>
 * @version $Revision$
 */
public class SkillScopeHandler implements Handler {
	
    SpriteService spriteService;
    SpritePool spritePool;

    public void setSpritePool(SpritePool spritePool) {
		this.spritePool = spritePool;
	}

	public void setSpriteService(SpriteService spriteService) {
        this.spriteService = spriteService;
    }

    public void process(ConnectSession session, CommandUp command) {
        SkillScopeUp cmd = (SkillScopeUp) command;
        //todo 1.判断技能是否合法

        //2.如果合法,则广播给指定范围(目前为全空间广播)
        SkillScopeDown down = new SkillScopeDown();
        down.skillId = cmd.skillId;
        down.sourceId = cmd.sourceId;
        down.targetX = cmd.targetX;
        down.targetY = cmd.targetY;
        down.targets = cmd.targets;
        down.damage = 40;
        if(cmd.targets != null){
        	for(int i=0 ; i<cmd.targets.length ; i++){
        		Sprite sp = spritePool.get(cmd.targets[i]);
            	if(sp != null){
            		sp.setHp(sp.getHp() - 40);        		
            	}        		
        	}
        }
        spriteService.broadcast(new Room(cmd.sceneId,cmd.sceneInstanceId),down);
    }
}